package com.arch.dev.server.dao.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.arch.dev.server.bean.Budget;
import com.arch.dev.server.dao.BudgetDao;

public class BudgetDaoImpl extends HibernateDaoSupport implements BudgetDao {

	public List<Budget> getAllValues() {

		List<Budget> budgetList = getHibernateTemplate().loadAll(Budget.class);

		return budgetList;

	}

	public void saveBudget(Budget budget) {

		getHibernateTemplate().saveOrUpdate(budget);

	}

	public void removeBudget(Budget budget) {

		getHibernateTemplate().delete(budget);

	}

	public List<Budget> getDataBetweenDates(Date startDate, Date endDate) {

		DetachedCriteria criteria = DetachedCriteria.forClass(Budget.class);

		criteria.add(Expression.between("date", new Date(startDate

		.getTime()), new Date(endDate.getTime())));

		return getHibernateTemplate().findByCriteria(criteria);

	}
	
	public List<Budget> getDataForDate (List<Date> dates) {

		DetachedCriteria criteria = DetachedCriteria.forClass(Budget.class);

		criteria.add(Expression.in("date",dates));

		return getHibernateTemplate().findByCriteria(criteria);

	}
	
}
